package com.hlkj.warboot.configurer.security.authentication.handler;

import com.hlkj.warboot.configurer.util.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 自定义登录失败回调函数
 * @Author 李星
 * @Date 2019/6/29 22:52
 */
@Component
public class MyAuthenticationFailHandler implements AuthenticationFailureHandler {

    /*
     * @Description 登陆失败
     * @Author 李星
     * @Date 2019/6/3 19:58
     * @Param [request, response, exception]
     * @return void
     */
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        ResponseUtil.outputJson( response, ResponseUtil.fail( exception.getMessage() ) );
    }
}
